This document aims to show how to use Diana to create wave spectra plots from Python scripts and from within the ipython notebook.
To get access to the Python modules that expose Diana's plotting features, you need to install the python-diana
package from the local package repository. Either use the package manager to do this, or enter the following in a
terminal:
apt-get install python-diana
Some examples can also be found in the python-diana-examples
package.
You can use Diana's functionality from Python by importing the bdiana
and plotcommands
modules from the metno
package. If you are using
an old version of ipython (earlier than version 1.0) then it is also useful to import the embed
function from the
metno.ipython_extensions
module.
In [1]:
# Import the modules needed to use Diana.
from metno import bdiana, plotcommands
# Import an extension that lets us embed an image into a worksheet.
from metno.ipython_extensions import embed
In [2]:
b = bdiana.BDiana()
b.setup("/etc/diana/setup/diana.setup-COMMON")
In [3]:
models = b.getSpectrumModels()
models
We select one of these models by calling the setSpectrumModel
method, then ask for the
list of stations for which there is wave spectrum data by calling the
getSpectrumStations
method.
In [4]:
b.setSpectrumModel(models[0])
stations = b.getSpectrumStations()
stations[:5]
We choose to display the data from a station by calling the setSpectrumStation
method
with the relevant station name. The available times for which data is available are
obtained by calling getSpectrumTimes
.
In [5]:
b.setSpectrumStation(stations[0])
times = b.getSpectrumTimes()
We set the time to use, using the last available time, by calling the setSpectrumTime
method before creating an image using the plotSpectrumImage
method, embedding the
result in this worksheet.
In [6]:
b.setSpectrumTime(times[-1])
spectrum_image = b.plotSpectrumImage(500, 500)
embed(spectrum_image)